package com.taobao.client.pages;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.taobao.client.buyer.custom.CustomButton;
import com.taobao.client.util.PopBox;

public class AddOrderMemo {

	static final Button closeButton = new Button("关闭");
	static DialogBox dialogBox;
	
	CustomButton customerButton;
	public AddOrderMemo(final CustomButton customerButton) {
		this.customerButton = customerButton;
	}
	
	public void show(){
		dialogBox = new DialogBox();
		dialogBox.setText("备注");
		dialogBox.setAnimationEnabled(true);

		// We can set the id of a widget by accessing its Element
		closeButton.getElement().setId("closeButton");

		VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.add(new HTML("<b>输入订单或子订单备注</b>"));
		
		final TextArea input = new TextArea();
		
		input.setSize("500px", "200px");
		
		
		dialogVPanel.add(input);
		
		final TextBox discount = new TextBox();
		dialogVPanel.add(new Label("折扣"));
		
		dialogVPanel.add(discount);
		
		Button addButton = new Button("添加备注并设置折扣");
		dialogVPanel.add(addButton);
		
		addButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent arg0) {
				
				String text = discount.getText();
				double parseInt = 0;
				try{
					parseInt = Double.parseDouble(text);
				}catch(Exception e){
					PopBox.error("折扣输入错误", "折扣输入错误");
				}
				customerButton.setDiscount(parseInt);
				customerButton.setMemo(""+input.getText());
				dialogBox.hide();
			}
		});

		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
		dialogVPanel.add(closeButton);
		dialogBox.setWidget(dialogVPanel);

		// Add a handler to close the DialogBox
		closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				dialogBox.hide();
			}
		});
		dialogBox.show();
		dialogBox.center();
	}
}
